home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / MAP Viewer / MAPLoader.h < prev    next >
C/C++ Source or Header  |  2003-10-09  |  5KB  |  197 lines

  1. /*
  2. Half-Life MAP viewing utility.
  3. Copyright (C) 2003  Ryan Samuel Gregg
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #pragma once
  21.  
  22. //#using <System.Windows.Forms.dll>
  23.  
  24. //using namespace System::Windows::Forms;
  25. using namespace System::IO;
  26.  
  27. __gc class CMainForm;
  28.  
  29. #include "stdafx.h"
  30. #include "World.h"
  31. #include "Entity.h"
  32. #include "Brush.h"
  33. #include "Face.h"
  34. #include "TextureManager.h"
  35.  
  36. #define LineTypeEmpty 0
  37. #define LineTypeOpenBrace 1
  38. #define LineTypeCloseBrace 2
  39. #define LineTypeArgVal 3
  40. #define LineTypeFace 4
  41.  
  42. //enum MAPLineType { Empty, OpenBrace, CloseBrace, ArgVal, Face };
  43.  
  44. __gc class CMAPLoader
  45. {
  46. private:
  47.     int iLine;
  48.  
  49.     CConfig *Config;
  50.     CRichTextBox *txtConsole;
  51.  
  52. public:
  53.     CMAPLoader(CConfig *Config, CRichTextBox *txtConsole);
  54.     bool LoadMAPFile(String *sFile, CWorld *World, CTextureManager *TextureManager);
  55.  
  56. private:
  57.     bool ReadEntity(StreamReader *MAPFile, CEntity *Entity, CTextureManager *TextureManager);
  58.     bool ReadBrush(StreamReader *MAPFile, CBrush *Brush, CTextureManager *TextureManager);
  59.     int ProcessLine(String **sLine);
  60.  
  61.     static String *SpecialTextures[] = { S"null", S"aaatrigger", S"origin", S"sky", S"clip", S"hint", S"skip" };
  62.  
  63. private:
  64.     typedef __gc struct CMAPFace
  65.     {
  66.     public:
  67.         CMAPFace(Vector *V1, Vector *V2, Vector *V3, String *Texture, Vector *AxisU, Vector *AxisV, Vertex2f Shift, Vertex2f Scale, float Rotation)
  68.         {
  69.             this->V1 = V1;
  70.             this->V2 = V2;
  71.             this->V3 = V3;
  72.  
  73.             this->Texture = Texture;
  74.  
  75.             this->AxisU = AxisU;
  76.             this->AxisV = AxisV;
  77.             this->Shift.X = Shift.X;
  78.             this->Shift.Y = Shift.Y;
  79.             this->Scale.X = Scale.X;
  80.             this->Scale.Y = Scale.Y;
  81.             this->Rotation = Rotation;
  82.         }
  83.  
  84.         Vector *V1;
  85.         Vector *V2;
  86.         Vector *V3;
  87.  
  88.         String *Texture;
  89.  
  90.         Vector *AxisU;
  91.         Vector *AxisV;
  92.         Vertex2f Shift;
  93.         Vertex2f Scale;
  94.         float Rotation;
  95.     } CMAPFace;
  96.  
  97.     typedef __gc struct CPlane
  98.     {
  99.     public:
  100.         CPlane(Vector *Normal, float Distance)
  101.         {
  102.             this->Normal = Normal;
  103.             this->Distance = Distance;
  104.         }
  105.  
  106.         Vector *Normal;
  107.         float Distance;
  108.  
  109.         /*                          -1
  110.         |x|     | n1.x n1.y n1.z |     |k1|
  111.         |y|  =  | n2.x n2.y n2.z |  X  |k2|
  112.         |z|     | n3.x n3.y n3.z |     |k3|
  113.         */
  114.         static bool GetIntersection(CPlane *P1, CPlane *P2, CPlane *P3, Vector *V)
  115.         {
  116.             //float fDenom = P1->Normal->Dot(P2->Normal->Cross(P3->Normal));
  117.  
  118.             //if(fDenom == 0.0f)
  119.                 //return false;
  120.  
  121.             float fDet;
  122.             float MN[9] = { P1->Normal->X, P1->Normal->Y, P1->Normal->Z, P2->Normal->X, P2->Normal->Y, P2->Normal->Z, P3->Normal->X, P3->Normal->Y, P3->Normal->Z };
  123.             float IMN[9] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
  124.             float MD[3] = { P1->Distance, P2->Distance , P3->Distance };
  125.  
  126.             //fDet = MN[0] * (MN[4] * MN[8] - MN[5] * MN[7]);
  127.             //fDet += -MN[1] * (MN[3] * MN[8] - MN[5] * MN[6]);
  128.             //fDet += MN[2] * (MN[3] * MN[7] - MN[4] * MN[6]);
  129.  
  130.             /*fDet = MN[0] * MN[4] * MN[8]
  131.                  + MN[1] * MN[5] * MN[6]
  132.                  + MN[2] * MN[3] * MN[7] 
  133.                  - MN[2] * MN[4] * MN[6]
  134.                  - MN[0] * MN[5] * MN[7]
  135.                  - MN[1] * MN[3] * MN[8];*/
  136.  
  137.             IMN[0] = MN[4] * MN[8] - MN[5] * MN[7];
  138.             IMN[3] = -(MN[3] * MN[8] - MN[5] * MN[6]);
  139.             IMN[6] = MN[3] * MN[7] - MN[4] * MN[6];
  140.  
  141.             fDet = MN[0] * IMN[0] + MN[1] * IMN[3] + MN[2] *IMN[6];
  142.  
  143.             if(fDet == 0.0f)
  144.                 return false;
  145.  
  146.             IMN[1] = -(MN[1] * MN[8] - MN[2] * MN[7]);
  147.             IMN[4] = MN[0] * MN[8] - MN[2] * MN[6];
  148.             IMN[7] = -(MN[0] * MN[7] - MN[1] * MN[6]);
  149.             IMN[2] = MN[1] * MN[5] - MN[2] * MN[4];
  150.             IMN[5] = -(MN[0] * MN[5] - MN[2] * MN[3]);
  151.             IMN[8] = MN[0] * MN[4] - MN[1] * MN[3];
  152.  
  153.             fDet = 1.0f / fDet;
  154.  
  155.             IMN[0] *= fDet;
  156.             IMN[1] *= fDet;
  157.             IMN[2] *= fDet;
  158.             IMN[3] *= fDet;
  159.             IMN[4] *= fDet;
  160.             IMN[5] *= fDet;
  161.             IMN[6] *= fDet;
  162.             IMN[7] *= fDet;
  163.             IMN[8] *= fDet;
  164.  
  165.             V->X = IMN[0] * MD[0] + IMN[1] * MD[1] + IMN[2] * MD[2];
  166.             V->Y = IMN[3] * MD[0] + IMN[4] * MD[1] + IMN[5] * MD[2];
  167.             V->Z = IMN[6] * MD[0] + IMN[7] * MD[1] + IMN[8] * MD[2];
  168.  
  169.             return true;
  170.         }
  171.     } CPlane;
  172.  
  173.     __gc class CMAPFaceManager
  174.     {
  175.     private:
  176.         ArrayList *MAPFaces;
  177.  
  178.     public:
  179.         CMAPFaceManager()
  180.         {
  181.             MAPFaces = new ArrayList();
  182.         }
  183.  
  184.         void AddMAPFace(CMAPFace *MAPFace)
  185.         {
  186.             MAPFaces->Add(MAPFace);
  187.         }
  188.  
  189.         ArrayList *GetMAPFaces()
  190.         {
  191.             return MAPFaces;
  192.         }
  193.     };
  194.  
  195. private:
  196.     void BuildBrushFaces(CMAPFaceManager *MAPFaceManager, CBrush *Brush, CTextureManager *TextureManager);
  197. };